package com.itcoon.cloud.framework.webmvc.response;

import com.itcoon.cloud.framework.enums.CommonResponseCode;
import com.itcoon.cloud.framework.page.IPageResult;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

/**
 * <p> </p>
 *
 * @author 俞淼霞
 * @since 2019-09-03
 */
@Schema
public class ApiPageResponse<T> extends ApiResponse<T> {

    /**
     * 总记录数
     */
    @Schema(description = "总记录数")
    private Long total;

    public ApiPageResponse() {
        super();
    }

    public static <T> ApiPageResponse<List<T>> ok(IPageResult<T> pageResult) {
        ApiPageResponse<List<T>> response = new ApiPageResponse<>();
        response.setCode(CommonResponseCode.OK.getCode());
        response.setMessage(CommonResponseCode.OK.getMessage());
        if(pageResult != null){
            response.setTotal(pageResult.getTotal());
            response.setData(pageResult.getRecords());
        }
        response.setTotal(pageResult.getTotal());
        return response;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    @Override
    public String toString() {
        return "ApiPageResponse{" +
                "total=" + total +
                ", super=" + super.toString() +
                '}';
    }
}
